package fenetre;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;

import metier.CL_genre;

public class CL_ajt_genre extends JFrame implements MouseListener , ActionListener{
	private JTextField Txt_genre;
	private CL_genre o_genre ;
	public CL_ajt_genre() {
		
		Txt_genre = new JTextField();
		Txt_genre.setColumns(10);
		
		JButton btnAjouter = new JButton("Ajouter");
		btnAjouter.addActionListener(this);
		btnAjouter.addActionListener(new ActionListener() 
		{ 
				public void actionPerformed(ActionEvent e) { }	
		});
		
		JLabel lblAjouterUnGenre = new JLabel("Ajouter un genre de musique");
		
		JLabel lblGenre = new JLabel("Genre");
		
		o_genre = new CL_genre();
		
		
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(btnAjouter)
							.addGap(12))
						.addGroup(Alignment.LEADING, groupLayout.createParallelGroup(Alignment.LEADING)
							.addGroup(groupLayout.createSequentialGroup()
								.addComponent(lblGenre)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(Txt_genre))
							.addComponent(lblAjouterUnGenre)))
					.addContainerGap(60, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblAjouterUnGenre)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(Txt_genre, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblGenre))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnAjouter)
					.addContainerGap(85, Short.MAX_VALUE))
		);
		getContentPane().setLayout(groupLayout);
	}{

}

@Override
public void actionPerformed(ActionEvent e) {	
	
	String nomBouton = e.getActionCommand();
	System.out.println("falemazdzd");
	if (nomBouton == "Ajouter")
	{
		String genre = this.Txt_genre.getText();
		
		int id_genre = 0; 
		id_genre = this.o_genre.m_add_genre(genre);
		if(id_genre != 0)
		{
			dispose();
		}
		
	}
	
}

@Override
public void mouseClicked(MouseEvent e) {
	// TODO Auto-generated method stub
	
}

@Override
public void mouseEntered(MouseEvent e) {
	// TODO Auto-generated method stub
	
}

@Override
public void mouseExited(MouseEvent e) {
	// TODO Auto-generated method stub
	
}

@Override
public void mousePressed(MouseEvent e) {
	// TODO Auto-generated method stub
	
}

@Override
public void mouseReleased(MouseEvent e) {
	// TODO Auto-generated method stub
	
}
}
